﻿using System;
using System.Xml.Linq;
using IBatisNet.DataMapper.TypeHandlers;
using Shop.Core.Domain.Common;

namespace Shop.Data.IBatis.TypeHandlers
{
    public class MoneyHandler : ITypeHandlerCallback
    {
        public object GetResult(IResultGetter getter)
        {
            decimal v = 0M;
            if (getter.Value != System.DBNull.Value)
            {
                v = (decimal)getter.Value;
            }
            return new Money(v);
        }

        public void SetParameter(IParameterSetter setter, object parameter)
        {
            Money m = (Money)parameter;
            setter.Value = m.Value;

        }

        public object ValueOf(string s)
        {
            return null;
        }

        public object NullValue
        {
            get
            {
                return Money.Zero;
            }
        }
    }
}